const ajax = require('../../../utils/ajax/ajax.js')
const util = require('../../../utils/util.js')
Page({
    data: {
        resData: {}
        // 0申请（确认中） 1通过（认购成功） 2拒绝（顺延中）3申请退款 4已退款 5拒绝退款
    },
    props: {
        buyId: ''
    },
    onLoad: function (options) {
        const  buyId= options.buyId
        this.props.buyId = buyId
        this.getApplyDetail()
    },
    getApplyDetail() {
        const that = this
        ajax.post({
            url: '/wx/getApplyDetail',
            data: {
                id: that.props.buyId
            },
            success(res) {
                const data = res.data
                
                that.setData({
                    resData: data
                })
                console.log(that.data.resData.status);
            }
        })
    },
    // 确认中 顺延中 弹框
    showPopup() {
        this.showStatusPopup()
    },
    showStatusPopup() {
        const popupConfirm = this.selectComponent('#popupStatus');
        popupConfirm.showPopup();
    },

    // 申请退款弹窗
    showRefundPopup() {
        const popupRefund = this.selectComponent('#popupRefund');
        popupRefund.showPopup();
    },
    refundCancel() {
        this.showRefundPopup()
    },
    refundConfirm() {
        const that = this
        this.showRefundPopup()
        ajax.post({
            url: '/wx/cancelApply',
            data: {
                id: that.props.buyId
            },
            success() {
                wx.navigateTo({
                    url: '/pages/Mine/proRefundSuccess/proRefundSuccess',
                })   
            },
            fail(err) {
                util.toast(err.msg)
            }
        })
    },

    // 跳转补填凭证
    toMakeVoucher() {
        const buyId = this.props.buyId
        wx.navigateTo({
          url: '/pages/Mine/makeVoucher/makeVoucher?buyId=' + buyId,
        })
    },

    // 申请退款
    refund() {
        const popupRefund = this.selectComponent('#popupRefund')
        popupRefund.showPopup()
    }
})